$(document).ready(function(){
		//日期控件调用
		$('#beginTime,#endTime').calendar();
		
		/*JQuery 限制文本框只能输入数字和小数点 */
		$("#claHour,#bookFee").keyup(function(){
        	$(this).val($(this).val().replace(/[^0-9.]/g,''));
        }).bind("paste",function(){  //CTR+V事件处理
            $(this).val($(this).val().replace(/[^0-9.]/g,'')); 
        }).css("ime-mode", "disabled"); //CSS设置输入法不可用
		
		/*JQuery 限制文本框只能输入数字 */
		$("#perunitFee,#claNum,#predictNum").keyup(function(){
			$(this).val($(this).val().replace(/\D|^0/g,''));
			//自动算出总课时费用
			var perunitFee = trim($("#perunitFee").val());
			var claNum = trim($("#claNum").val());
			if(perunitFee.length > 0 && claNum.length > 0){
				$("#totalUnitFee").attr("value",perunitFee*claNum);
			}else{
				$("#totalUnitFee").attr("value","");
			}
		}).bind("paste",function(){
			$(this).val($(this).val().replace(/\D|^0/g,''));
		}).css("ime-mode", "disabled");
		
		//漂亮的蓝色提示哈
		$('.skyblue').poshytip({
			className: 'tip-skyblue',
			bgImageFrameSize: 9,
			offsetX: 0,
			offsetY: 20
		});
});

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

//用ajax进行数据添加
function addCourse(){
	var path = $("#path").val()+"/AddCourse.action";
	var year = $("#year").val();
	var term = $("#term").val();
	var graname = $("#graname").val();
	var subject = $("#subject").val();
	var beginTime = $("#beginTime").val();
	var endTime = $("#endTime").val();
	var claHour = $("#claHour").val();
	var claNum = $("#claNum").val();
	var claType = $("#claType").val();
	var claLevel = $("#claLevel").val();
	var perunitFee = $("#perunitFee").val();//单课次费用
	var predictNum = $("#predictNum").val();//预招人数
	var bookFee = $("#bookFee").val();	//书本费
	var bookVersion = $("#bookVersion").val();  //教材版本
	var claTime = $("#claTime").val();  //上课时间
	
	if(trim(claHour).length <= 0){
		$.dialog.tips('课时数不可为空！',3,'alert.gif');
	}else if(trim(bookFee).length <= 0){
		$.dialog.tips('书本费用不可为空！',3,'alert.gif');
	}else if(trim(predictNum).length <= 0){
		$.dialog.tips('预计招生人数不可为空！',3,'alert.gif');
	}else if(trim(claNum).length <= 0){
		$.dialog.tips('上课次数不可为空！',3,'alert.gif');
	}else if(trim(perunitFee).length <= 0){
		$.dialog.tips('单课次费用不可为空！',3,'alert.gif');
	}else{
		$.ajax({
		      type: "post",
		      url: path,
		      cache: false,
		      dataType: "json",
		      data: "year="+year+
		      "&term="+encodeURI(encodeURI(term))+
		      "&graname="+encodeURI(encodeURI(graname))+
		      "&subject="+encodeURI(encodeURI(subject))+
		      "&beginTime="+encodeURI(encodeURI(beginTime))+
		      "&endTime="+encodeURI(encodeURI(endTime))+
		      "&claType="+encodeURI(encodeURI(claType))+
		      "&claLevel="+encodeURI(encodeURI(claLevel))+
		      "&bookVersion="+encodeURI(encodeURI(bookVersion))+
		      "&claTime="+claTime+
		      "&bookFee="+bookFee+
		      "&claNum="+claNum+
		      "&claHour="+claHour+
		      "&perunitFee="+perunitFee+
		      "&predictNum="+predictNum,
		      
		      //发送数据之前
		      beforeSend: function(){$.dialog.tips('正在添加数据...',3,'loading.gif');},
		      success: function(result){
		    	  if(result){
		    		  $.dialog.tips('添加成功！',3,'success.gif');
		    		  window.location.href=$("#path").val()+"/syscourselist.jsp";
		    	  }else{
		    		  $.dialog.tips('您好，添加失败，请联系管理员处理！',3,'error.gif');
		    	  }
		      }
			});
	}
}
//修改
function upCourse(){
	var path = $("#path").val()+"/UpCourse.action";
	var id = $("#id").val();
	var year = $("#year").val();
	var term = $("#term").val();
	var graname = $("#graname").val();
	var subject = $("#subject").val();
	var beginTime = $("#beginTime").val();
	var endTime = $("#endTime").val();
	var claHour = $("#claHour").val();
	var claNum = $("#claNum").val();
	var claType = $("#claType").val();
	var claLevel = $("#claLevel").val();
	var perunitFee = $("#perunitFee").val();//单课次费用
	var predictNum = $("#predictNum").val();//预招人数
	var bookFee = $("#bookFee").val();	//书本费
	var bookVersion = $("#bookVersion").val();  //教材版本
	var claTime = $("#claTime").val();  //上课时间
	
	if(trim(claHour).length <= 0){
		$.dialog.tips('课时数不可为空！',3,'alert.gif');
	}else if(trim(bookFee).length <= 0){
		$.dialog.tips('书本费用不可为空！',3,'alert.gif');
	}else if(trim(predictNum).length <= 0){
		$.dialog.tips('预计招生人数不可为空！',3,'alert.gif');
	}else if(trim(claNum).length <= 0){
		$.dialog.tips('上课次数不可为空！',3,'alert.gif');
	}else if(trim(perunitFee).length <= 0){
		$.dialog.tips('单课次费用不可为空！',3,'alert.gif');
	}else{
		$.ajax({
		      type: "post",
		      url: path,
		      cache: false,
		      dataType: "json",
		      data: "id="+id+
		      "&year="+year+
		      "&term="+encodeURI(encodeURI(term))+
		      "&graname="+encodeURI(encodeURI(graname))+
		      "&subject="+encodeURI(encodeURI(subject))+
		      "&beginTime="+encodeURI(encodeURI(beginTime))+
		      "&endTime="+encodeURI(encodeURI(endTime))+
		      "&claType="+encodeURI(encodeURI(claType))+
		      "&claLevel="+encodeURI(encodeURI(claLevel))+
		      "&bookVersion="+encodeURI(encodeURI(bookVersion))+
		      "&claTime="+claTime+
		      "&bookFee="+bookFee+
		      "&claNum="+claNum+
		      "&claHour="+claHour+
		      "&perunitFee="+perunitFee+
		      "&predictNum="+predictNum,
		      
		      //发送数据之前
		      beforeSend: function(){$.dialog.tips('正在更新数据...',3,'loading.gif');},
		      success: function(result){
		    	  if(result){
		    		  $.dialog.tips('修改成功！',3,'success.gif');
		    		  window.location.href=$("#path").val()+"/syscourselist.jsp";
		    	  }else{
		    		  $.dialog.tips('您好，修改失败，请联系管理员处理！',3,'error.gif');
		    	  }
		      }
			});
	}
}
//清空
function reset(){
	$("#beginTime,#endTime,#predictNum,#perunitFee,#claHour,#claNum," +
			"#bookFee,#totalUnitFee").val("");
	$.dialog.tips('已清空！',2,'confirm.gif');
}

